use kps::constant::{earth, LogLevel, Star};
use kps::math::integration;
use kps::model::auto_logic::DefaultAutoLogic;
use kps::model::rocket::{Engine, Mount, Rocket, RocketInfo};

fn main() {
    running();
}


/// 时间 time / s
/// 距离 distance / m
fn running() {
    let mut time: u128 = 0;
    let star = earth::Earth;
    let grand = star.info().radius;
    let mut distance: f64 = grand + 0.1;
    let mut speed: f64 = 0.0;
    let mut rocket = Rocket::new(
        RocketInfo::new("SA".to_string(), 21.0e+3, 0.4, 12.4),
        vec![Engine::new("base".to_string(), 12.0e+3, 420.0e+3, 8)],
        vec![Mount::new(800.0, 15000, 0.6)],
    );

    let mut max = distance;

    loop {
        let log = time % (10) == 0;
        if log {
            println!("- current time: {}min, distance: {}km", time / (60), distance / 1000.0);
        }
        let result = integration::exec(
            &star,
            &mut rocket,
            DefaultAutoLogic,
            time,
            distance,
            speed,
            if log { LogLevel::TOTAL } else { LogLevel::NONE },
        );
        distance = result.0;
        speed = result.1;
        time += 1;
        //sleep
        // std::thread::sleep(Duration::from_micros(1));
        if log {
            println!("\n");
        }
        max = max.max(distance);
        if distance == grand {
            println!("the farthest distance : {}km", max / 1000.0);
            break;
        }
    }
}

